package myTargetCodeGen;

import bit.minisys.minicc.MiniCCCfg;
import bit.minisys.minicc.icgen.ExampleICPrinter;
import bit.minisys.minicc.icgen.IMiniCCICGen;
import bit.minisys.minicc.internal.util.MiniCCUtil;
import bit.minisys.minicc.parser.ast.ASTCompilationUnit;
import com.fasterxml.jackson.databind.ObjectMapper;
import myICGen.MyICBuilder;

import java.io.File;

public class MyNCGen implements IMiniCCICGen {
    @Override
    public String run(String iFile) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        ASTCompilationUnit program = (ASTCompilationUnit)mapper.readValue(new File(iFile), ASTCompilationUnit.class);
        MyNCBuilder ncBuilder = new MyNCBuilder();
        ASMProgram asmProgram = ncBuilder.startGenCode(program);

        String oFile = MiniCCUtil.remove2Ext(iFile) + MiniCCCfg.MINICC_CODEGEN_OUTPUT_EXT;

        asmProgram.ASMProgramOut(oFile);
        return oFile;
    }
}
